<template>
   <div>
       <el-form :model="notices" ref="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
           <el-form-item label="* 标题：" prop="title"><el-input v-model="notices.title"/> </el-form-item>
           <el-form-item label="* 日期：" prop="date">
               <el-date-picker
                       v-model="notices.noticeNotificationtime"
                       type="datetime"
                       placeholder="选择日期时间"
                       value-format="yyyy-MM-dd HH:mm:ss">
               </el-date-picker>
           </el-form-item>
           <el-form-item label="* 结束日期：" prop="date1">
               <el-date-picker
                       v-model="notices.noticeNotificationendtime"
                       align="right"
                       type="datetime"
                       placeholder="选择日期"
                       value-format="yyyy-MM-dd HH:mm:ss"
               >
               </el-date-picker>
           </el-form-item>
           <!--http://localhost/upload 云端的路径-->
           <!--:headers="{token:this.$store.state.token}" 获取当前人的token-->
           <!-- :data="{folder:'notice'}" 创建自己的文件夹 名字为 notice-->
           <!--:on-success="handleUploadSuccess" 上传成功的回调方法 名字 handleUploadSuccess-->
           <el-container>
               <el-form-item label="相关文件">
                   <el-upload
                           class="upload-demo"
                           drag
                           name="multipartfile"
                           action="http://localhost/upload"
                           :headers="{token:this.$store.state.token}"
                           :data="{folder:'notice'}"
                           :on-success="handleUploadSuccess">
                       <i class="el-icon-upload"></i>
                       <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                   </el-upload>
               </el-form-item>
               <!--写一个隐藏框 来储存路径 属性名称 notices.noticeFile-->
               <el-input v-model="notices.noticeFile" v-show="false"></el-input>
           </el-container>
           <el-form-item label="* 通知内容：" prop="notice">
               <el-input
                       type="textarea"
                       :rows="3"
                       placeholder="请输入内容"
                       v-model="notices.noticeContent">
               </el-input>
           </el-form-item>
               <el-form-item>
                  <el-button type="primary" @click="Addnotices('ruleForm')" :disabled="disabled">确定</el-button>
                           <el-button @click="rove">取消</el-button>
               </el-form-item>
       </el-form>
   </div>
</template>

<script>
    export default {
        name: "AdmNoticeAdd",
        props:["notice","ad"],
        data() {
            var title = (rule, value, callback) => {
                value=this.notices.title;
                if (!value) {
                    callback(new Error('请输入标题'));
                } else {
                    callback();
                    this.disabled=false;
                }
            };var date = (rule, value, callback) => {
                value=this.notices.noticeNotificationtime;
                if (!value) {
                    callback(new Error('请输入日期'));
                } else {
                    callback();
                    this.disabled=false;
                }
            };var date1 = (rule, value, callback) => {
                value=this.notices.noticeNotificationendtime;
                if (!value) {
                    callback(new Error('请输入日期'));
                } else {
                    callback();
                    this.disabled=false;
                }
            };var noticeContent = (rule, value, callback) => {
                value=this.notices.noticeContent;
                if (!value) {
                    callback(new Error('请输入通知内容'));
                } else {
                    callback();
                    this.disabled=false;
                }
            };

            return {
                disabled:true,
                notices:JSON.parse(JSON.stringify(this.notice)),
                ads:JSON.parse(JSON.stringify(this.ad)),
                rules: {
                    title: [{ validator: title, trigger: 'blur' }],
                    date: [{ validator: date, trigger: 'blur' }],
                    date1: [{ validator: date1, trigger: 'blur' }],
                    notice: [{ validator: noticeContent, trigger: 'blur' }]
                }
            };
        },
        methods: {
            //文件上传成功的回调
            handleUploadSuccess(response){
                //给隐藏框的字段赋值
                this.notices.noticeFile = response.data
            },
            rove(){
                this.$emit("roves",this.ads=1)
            },
            Addnotices(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$emit("update",this.notices)
                        this.notices={};
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            },
        }

    }
</script>

<style scoped>

</style>